package PrecticeAm;

public class isAddcount {
    int num;
    int[] arr;
    int[] number;

    public int isAdd(int num) {
        int sum = 0;
        for (int i = 1; i <= num; i++) {
            int count = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    count++;
                }
                if (count > 2) {
                    continue;
                }
            }
            if (count == 2) {
                sum += i;
            }
        }
        return sum;
    }

    public void Change(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            int current = arr[i + 1];
            int index = i; // 认为已经排好序的最大下标
            // 结束的条件是 index < 0 或者 current 大于 arr[index]
            for (;index >= 0 && current < arr[index]; index--) {
                arr[index + 1] = arr[index];
            }
            arr[index + 1] = current;
        }
    }

    public int binarySearch(int[] arr1, int key) {
        int start = 0;
        int end = arr1.length - 1;
        while (start <= end) {
            int mid = (start + end) / 2;  // 中间的下标
            if (arr1[mid] == key) {
                return mid;
            } else if (arr1[mid] > key) {
                end = mid - 1;
            } else {
                start = mid + 1;
            }
        }

        return -1;
    }
}
